
package com.tools.cleanmaster.model.item;

import android.os.Build;
import android.text.TextUtils;

import com.tools.cleanmaster.utils.LogHelper;
import com.tools.cleanmaster.utils.OptimizerFile;
import com.tools.cleanmaster.utils.TrashUtils;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * 应用垃圾
 */
public class AppTrashItem extends TrashItem implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final int APP_TYPE_OTHERS = 0; // 其它常用软件
    public static final int APP_TYPE_NETWORK = 1; // 上网、聊天
    public static final int APP_TYPE_MEDIA = 2; // 看视频、听音乐
    public static final int APP_TYPE_MAP = 3; // 地图、导航

    public static final int FILE_TYPE_UNKNOWN = 0; // 未知
    public static final int FILE_TYPE_MUSIC = 1; // 音乐
    public static final int FILE_TYPE_VIDEO = 2; // 视频
    public static final int FILE_TYPE_IMAGE = 3; // 图片
    public static final int FILE_TYPE_DATA = 4; // 数据
    public static final int FILE_TYPE_CACHE = 5; // 缓存
    public static final int FILE_TYPE_DOWNLOAD = 6; // 下载

    public static final int CLEAN_SUGGEST_RESERVE = 0; // 建议保留
    public static final int CLEAN_SUGGEST_CLEAN = 1; // 一键清理

    private static final String TAG = "AppTrashItem";


    public String pathDesp;
    public String alertInfo;
    public int cleanSuggest;
    public int contentType;
    public String itemName;
    public ArrayList<String> regularPaths;
    public boolean isRegular;

    @Override
    public void clean() {
        if (isRegular && regularPaths != null) {
            for (String regularPath : regularPaths) {
                if (TextUtils.isEmpty(regularPath)) {
                    continue;
                }

                if (TrashUtils.isUseJniFunction() && Build.VERSION.SDK_INT != 19) {
                    TrashUtils.deleteFileJni(new File(regularPath), null);
                } else {
                    TrashUtils.deleteFile(new OptimizerFile(regularPath));
                }
            }
            cleanedFlag = true;
        } else if (!isRegular) {
            super.clean();
        } else {
            LogHelper.d(TAG, "AppTrashItem" + " clean regular is error !");
        }
    }
}
